<h3 mat-dialog-title>
  {{ 'Reboot Required' | translate }}
</h3>

<div mat-dialog-content>
  @if (isHaLicensed() && !canFailover()) {
    <div class="failover-reasons">
      <p class="dialog-message error">
        <span>{{ 'Failover is unhealthy. Rebooting now will cause a production outage.' | translate }}</span>
      </p>

      @for (reason of failoverDisabledReasons(); track reason) {
        <li>
          {{ reason | mapValue: disabledReasonExplanations | translate }}
        </li>
      }
    </div>
  }

  @if(thisNodeRebootReasons()?.length) {
    <div class="reasons">
      <p class="dialog-message">
        <span>
          @if (isHaLicensed()) {
            {{ 'Active Controller must be rebooted because' | translate }}:
          } @else {
            {{ 'The local node must be rebooted because' | translate }}:
          }
        </span>
      </p>
      @for (reason of thisNodeRebootReasons(); track reason) {
        <li> {{ reason.reason }} </li>
      }
    </div>
  }

  @if(otherNodeRebootReasons()?.length) {
    <div class="reasons">
      <p class="dialog-message">
        <span>
          @if (isHaLicensed()) {
            {{ 'Standby Controller must be rebooted because' | translate }}:
          } @else {
            {{ 'The remote node must be rebooted because' | translate }}:
          }
        </span>
      </p>
      @for (reason of otherNodeRebootReasons(); track reason) {
        <li> {{ reason.reason }} </li>
      }
    </div>
  }
</div>

@if (thisNodeRebootReasons()?.length || otherNodeRebootReasons()?.length) {
  <ix-form-actions mat-dialog-actions class="form-actions">
    <ix-checkbox
      class="confirm"
      [formControl]="form.controls.confirm"
      [label]="'Confirm' | translate"
      [required]="true"
    ></ix-checkbox>

    <button mat-button type="button" matDialogClose ixTest="cancel">
      {{ 'Cancel' | translate }}
    </button>

    @if(thisNodeRebootReasons()?.length) {
      <button
        mat-button
        color="primary"
        ixTest="reboot-local"
        [disabled]="form.invalid"
        (click)="rebootLocalNode()"
      >
        @if (isHaLicensed()) {
          {{ 'Reboot Active Controller' | translate }}
        } @else {
          {{ 'Reboot Local' | translate }}
        }
      </button>
    }

    @if (otherNodeRebootReasons()?.length) {
      <button
        mat-button
        color="primary"
        ixTest="reboot-remote"
        [disabled]="form.invalid"
        (click)="rebootRemoteNode()"
      >
        @if (isHaLicensed()) {
          {{ 'Reboot Standby Controller' | translate }}
        } @else {
          {{ 'Reboot Remote' | translate }}
        }
      </button>
    }
  </ix-form-actions>
}
